package NiuKe;

import java.io.InputStream;
import java.util.Scanner;

/**
 * 2.序号4
 * 有n个人围成一圈，顺序排号。
 * 从第一个人开始报数（从1到3报数），
 * 凡报到3的人退出圈子，问最后留下的是原来第几号的那位。
 *
 * 5: 1 2 3 4 5
 * 3
 * 1
 * 5
 * 2
 */
public class XuHao4 {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int n = scanner.nextInt();
        int result = Solution(n);
        System.out.println(result);
    }
    public static int Solution(int n){
        int[] people = new int[n];
        for(int i = 0;i < n;i++){
            people[i] = i + 1;
        }
        int count = 0;
        int target = 1;
        int zhiZhen = 0;
        while (count < n - 1){
            if(zhiZhen > n - 1){
                zhiZhen = 0;
            }
            if (people[zhiZhen] != -1){
                if(target < 3){
                    target++;
                }else {
                    people[zhiZhen] = -1;
                    target = 1;
                    count++;
                }
            }
            zhiZhen++;
        }
        int result = 0;
        for (int p : people) {
            if(p != -1){
                result = p;
                break;
            }
        }
        return result;
    }
}
